Skip to content

fix(#1438): preserve json flag for MariaDB longtext-aliased columns#1443

Merged
dimitri-yatsenko merged 1 commit intomasterfrom
fix/1438-json-mariadb-longtext
Apr 30, 2026
Merged

fix(#1438): preserve json flag for MariaDB longtext-aliased columns#1443
dimitri-yatsenko merged 1 commit intomasterfrom
fix/1438-json-mariadb-longtext

Conversation

@dimitri-yatsenko
Copy link
Copy Markdown
Member

@dimitri-yatsenko dimitri-yatsenko commented Apr 29, 2026

Summary

Fixes #1438. MariaDB stores json columns as longtext and reports them back through information_schema as longtext, so DataJoint's DB-type-based JSON detection in Heading._init_from_database() left attr["json"] as False. That silently broke insert (json.dumps skipped → dict reaches pymysql → TypeError) and fetch (json.loads skipped → caller gets the raw string).

The :json: comment marker is already written at declare-time (JSON is in CORE_TYPE_NAMES / SPECIAL_TYPES) and already parsed back into attr["original_type"] on read. Recover attr["json"] from that marker in the same block where UUID is already recovered.

Behavior by backend

  • MySQL: DB reports json, regex matches, attr["json"] = True from the existing line. The new branch reasserts the same value — no behavior change.
  • PostgreSQL: DB reports json/jsonb, regex matches both. Same as MySQL — no-op.
  • MariaDB: DB reports longtext, regex misses, attr["json"] was False. The :json: comment marker is intact, so category == "JSON" and the new branch flips it to True. Insert and fetch now round-trip correctly.

Out of scope

  • Legacy MariaDB tables created without the :json: comment marker (e.g. created by a non-DataJoint tool) will still fail. Adding a heuristic for bare longtext columns would be unsound.
  • MariaDB CI coverage. MariaDB remains unofficially supported and will not be added to this repo's CI matrix. Downstream projects depending on MariaDB own MariaDB testing in their own pipelines.

Test plan

  • Round-trip the issue reproduction against a MariaDB container (insert dict, fetch back dict).
  • pytest tests/integration/test_json.py against MySQL — confirm no regression.
  • pytest tests/integration/test_json.py against PostgreSQL — confirm no regression.
  • Spot-check heading.attributes["metadata"].json is True and .type == "longtext" on MariaDB after the insert succeeds.

MariaDB stores `json` columns as `longtext` and reports them back through
information_schema as `longtext`, so the DB-type-based detection in
_init_from_database() leaves attr["json"] False. The :json: comment marker
written at declare-time survives the aliasing, so recover the json flag
from the original declared type alongside the existing UUID recovery.

No-op on MySQL/PostgreSQL where the regex match against the DB-reported
type already sets attr["json"] = True.
@dimitri-yatsenko dimitri-yatsenko merged commit a251f44 into master Apr 30, 2026
7 checks passed
@dimitri-yatsenko dimitri-yatsenko deleted the fix/1438-json-mariadb-longtext branch April 30, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

json columns on MariaDB: insert fails with TypeError, fetch returns raw strings

2 participants